package org.gof.application
{
	import com.iMANIT.DS.DubLinkedList.DLLnode;
	import com.iMANIT.DS.DubLinkedList.DubLinkedList;
	
	// Proxies allow framework access to data through appFacade.
	use namespace SetByAppNS;
	public class BaseReadProxy
	{
		private var subscriptions:DubLinkedList;
		protected var _app:BaseAppFacade;
		
		protected var writeProxy:BaseWriteProxy;
		protected var data:*;
		
		public function BaseReadProxy(wp:BaseWriteProxy)
		{
			writeProxy = wp;
			subscriptions = new DubLinkedList();
		}
		
		SetByAppNS function set application(a:BaseAppFacade):void
		{
			_app = a;
		}
		
		public function subcribeToBy(m:BaseMediator): void
		{
			subscriptions.insertEnding(m);
		}
			
		public function refreshAllData():void
		{
			if (writeProxy.subscribersOutdated)
			{
				var ptr:DLLnode = subscriptions.head;
				while (ptr != null)
				//for (var cntx:int = 0; cntx < subscritpions.length; cntx++)
				{
					var med:BaseMediator = ptr.payload as BaseMediator;
					if (med.lastUpdatedFrame < _app.mainClock.tickCount )
					{
							med.refreshData();
					}
					ptr = ptr.backward;
				
				}
			}
			writeProxy.subscribersOutdated = false;
		}
	}
}